﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
using RxjhServer.bbg;
using RxjhServer.DbClss;
using RxjhServer.HelperTools;
using RxjhServer.Network;

namespace RxjhServer
{
	public partial class Form1 : Form
	{
		private System.Timers.Timer 自动显示 = new System.Timers.Timer(1000.0);

		private System.Timers.Timer 狮子吼 = new System.Timers.Timer(21000.0);

		private System.Timers.Timer 自动连接;

		private int 自动公告ID;

		private static World world;

		private static List<TxtClass> txt = new List<TxtClass>();

		private DateTime sj = DateTime.Now;

		private Thread thThreadRead;

		private static Thread timerThread;

		private RxjhServer.Network.Listener T;

		private bool runn;

		private int aaa = 2;

		private static int kjdx = 300;

		public Form1()
		{
            
            this.InitializeComponent();
		}

		//[STAThread]
		//private static void Main(){
		//	try
		//	{
		//		Application.ThreadException += new ThreadExceptionEventHandler(Form1.Application_ThreadException);
		//		AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Form1.CurrentDomain_UnhandledException);
		//		Application.EnableVisualStyles();
		//		Application.SetCompatibleTextRenderingDefault(false);
		//		//Application.Run(new Form1());
		//		Ini ini = new Ini(Application.StartupPath + "\\config.ini");
		//		if (Aes.Decrypt(Aes.Key1, ini.GetString("Key1"))?.StartsWith(Aes.GetMachineCode()) == true &&
		//			Aes.Decrypt(Aes.Key2, ini.GetString("Key2"))?.StartsWith(Aes.GetMachineCode()) == true)
		//		{
		//			Application.Run(new Form1());
		//		}
		//		else
		//		{
		//			Application.Run(new Form1());
		//		}
		//		Application.ThreadException += new ThreadExceptionEventHandler(Form1.Application_ThreadException);
		//	}
		//	catch (Exception arg)
		//	{
		//		MessageBox.Show("Main 错误" + arg);
		//	}
		//}

		public static void Kill()
		{
			Process[] processes = Process.GetProcesses();
			Process[] array = processes;
			for (int i = 0; i < array.Length; i++)
			{
				Process process = array[i];
				process.Kill();
			}
		}

		private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
		{
			Form1.WriteLine(66, "未处理异常1:" + e.Exception);
		}

		private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			Form1.WriteLine(66, "未处理异常2:" + e.ExceptionObject + e.ToString());
		}
        public static string StrToHex(byte[] bytes)
        {
            StringBuilder stringBuilder = new StringBuilder(bytes.Length * 2);
            for (int i = 0; i < bytes.Length; i++)
            {
                byte b = bytes[i];
                stringBuilder.Append("0x" + b.ToString("X2") + ",");
            }
            return "{" + stringBuilder.ToString() + "}";
        }

        private void Form1_Load(object sender, EventArgs e)
		{
			try
			{

                //byte[] array2 = new byte[16];
                //for (int i = 0; i < array2.Length; i++)
                //{
                //    array2[i] = (byte)RNG.Next(1, 255);
                //}
                //string s = StrToHex(array2);

                RxjhServer.Timer.TimerThread @object = new RxjhServer.Timer.TimerThread();
				Form1.timerThread = new Thread(new ThreadStart(@object.TimerMain));
				Form1.timerThread.Name = "Timer Thread";
				Form1.timerThread.Start();
				Form1.world = new World();
			
				Form1.world.SetConfig();
                Form1.world.SetConfig2();
                //Form1.world.SetConfig3();
               // Form1.world.SetConfig4();
                if (World.检查数据库配置())
                {
					Form1.world.SetMonSter();
					Form1.world.SetNpc();
					Form1.world.SetDrop();
					Form1.world.Set_GSDrop();
					Form1.world.SetBossDrop();
					Form1.world.SetOpen();
					Form1.world.SetLever();
					Form1.world.SetPatLever();
					Form1.world.SetWxLever();
					Form1.world.SetKONGFU();
					Form1.world.SetItme();
					Form1.world.SetShot();
					Form1.world.SetMover();
                    Form1.world.Set石头属性();
					Form1.world.Set人物数据();
					Form1.world.SetDB首爆();
					Form1.world.Set公告();
					Form1.world.Set异口同声();
					Form1.world.Set移动();
					Form1.world.Set安全区();
					Form1.world.SetKill();
					Form1.world.Set冲关地图();
					Form1.world.SetBossInfo();
					Form1.world.Set百宝物品();
					Form1.world.set会员装备();
					Form1.world.Set套装物品();
					Form1.world.Set转职属性();
					Form1.world.Set冲级奖励物品();
					Form1.world.Set任务物品();
					Form1.world.SetScript();
					Form1.world.Set任务传书数据();
					World.conn = new Connect();
					World.conn.Sestup();
					World.游戏服务器端口1 = World.游戏服务器端口;
					this.T = new RxjhServer.Network.Listener((ushort)World.游戏服务器端口);
					new AuthServer(World.百宝阁服务器IP, World.百宝阁服务器端口);
					WGServer wGServer = new WGServer("127.0.0.1", World.转发器网关服务端口);
					wGServer.Start();
					RxjhServer.Timer.DelayCall(TimeSpan.FromMilliseconds(300000.0), TimeSpan.FromMilliseconds(300000.0), new TimerCallback(this.自动公告事件));
					this.Text = string.Concat(new string[]
					{
						this.Text,
						"_",
						World.服务器名,
						"_",
						World.游戏服务器端口.ToString(),
						"_",
						Assembly.GetExecutingAssembly().GetName().Version.ToString()
					});
					this.thThreadRead = new Thread(new ThreadStart(this.FlushAll));
					this.thThreadRead.Name = "FlushAll";
					this.thThreadRead.Start();
					this.狮子吼 = new System.Timers.Timer(21000.0);
					this.狮子吼.Elapsed += new ElapsedEventHandler(this.狮子吼事件);
					this.狮子吼.AutoReset = true;
					this.狮子吼.Enabled = true;
					this.自动连接 = new System.Timers.Timer((double)(World.自动连接时间 * 1000));
					this.自动连接.Elapsed += new ElapsedEventHandler(this.自动连接事件);
					this.自动连接.AutoReset = true;
					this.自动连接.Enabled = true;
                    ClassDllImport.LoadLib();
                }
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "Form1_Load 错误" + ex.Message);
			}
		}

		private void 自动存档线程(object ParObject)
		{
			try
			{
				List<Players> list = new List<Players>();
				foreach (Players current in World.allConnectedChars.Values)
				{
					list.Add(current);
				}
				foreach (Players current2 in list)
				{
					try
					{
						current2.保存人物的数据();
					}
					catch (Exception ex)
					{
						Form1.WriteLine(1, "保存人物的数据 错误" + ex.Message);
					}
				}
				list.Clear();
				Form1.WriteLine(8, "保存人物的数据 完成");
			}
			catch (Exception ex2)
			{
				Form1.WriteLine(1, "保存人物的数据 错误：" + ex2.Message);
			}
		}

		private void 自动连接事件(object source, ElapsedEventArgs e)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(0, "自动连接事件()");
			}
			this.自动连接.Interval = (double)(World.自动连接时间 * 1000);
			if (!World.主Socket)
			{
				if (this.T != null)
				{
					this.T.Stop();
					this.T = null;
				}
				Random random = new Random();
				World.游戏服务器端口1 = World.游戏服务器端口 + random.Next(10, 200);
				this.T = new RxjhServer.Network.Listener((ushort)World.游戏服务器端口1);
				World.端口更换通知();
			}
		}

		private void menuItem32_Click(object sender, EventArgs e)
		{
			if (World.conn != null)
			{
				World.conn.Dispose();
				World.conn = null;
			}
			World.conn = new Connect();
			World.conn.Sestup();
		}

		private void menuItem2_Click(object sender, EventArgs e)
		{
			if (this.T != null)
			{
				this.menuItem2.Text = "开始游戏服务";
				this.T.Stop();
				this.T = null;
				return;
			}
			this.menuItem2.Text = "停止游戏服务";
			Random random = new Random();
			World.游戏服务器端口1 = World.游戏服务器端口 + random.Next(10, 200);
			this.T = new RxjhServer.Network.Listener((ushort)World.游戏服务器端口1);
			World.端口更换通知();
		}

		private void menuItem3_Click(object sender, EventArgs e)
		{
			this.menuItem3.Text = "开始登陆服务";
			World.conn.Dispose();
			List<Players> list = new List<Players>();
			foreach (Players current in World.allConnectedChars.Values)
			{
				list.Add(current);
			}
			foreach (Players current2 in list)
			{
				try
				{
					current2.保存人物的数据();
					if (current2.Client != null)
					{
						current2.Client.Dispose();
					}
				}
				catch (Exception ex)
				{
					Form1.WriteLine(1, "保存人物的数据 错误" + ex.Message);
				}
			}
			list.Clear();
		}

		private void 狮子吼事件(object source, ElapsedEventArgs e)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(0, "狮子吼事件");
			}
			World.Process狮子吼Queue();
		}

		private void Form1_FormClosing(object sender, FormClosingEventArgs e)
		{
			try
			{
				if (World.SqlPool.Count > 0)
				{
					DialogResult dialogResult = MessageBox.Show("数据列队还没有完成 " + World.SqlPool.Count, "数据列队还没有完成", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
					int num = (int)dialogResult;
					if (num == 1)
					{
						this.runn = true;
						Form1.timerThread.Abort();
						this.thThreadRead.Abort();
						if (this.T != null)
						{
							this.T.Dispose();
							this.T = null;
						}
					}
					else
					{
						e.Cancel = true;
					}
				}
				else if (World.allConnectedChars.Count > 0)
				{
					DialogResult dialogResult2 = MessageBox.Show("有人物在线 " + World.allConnectedChars.Count, "还有人物在线", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
					int num2 = (int)dialogResult2;
					if (num2 == 1)
					{
						this.runn = true;
						Form1.timerThread.Abort();
						this.thThreadRead.Abort();
						if (this.T != null)
						{
							this.T.Dispose();
							this.T = null;
						}
					}
					else
					{
						e.Cancel = true;
					}
				}
				else
				{
					this.runn = true;
					Form1.timerThread.Abort();
					this.thThreadRead.Abort();
                    ClassDllImport.FreeLib();
                }
			}
			catch
			{
			}
		}

		private void FlushAll()
		{
			try
			{
				while (!this.runn)
				{
                    RxjhServer.Timer.Slice();
                    Thread.Sleep(1);
                    //World.ProcessDisposedQueue();
                    World.ProcessSqlQueue();
                    if (World.自动开启换端口 && World.list.Count - World.allConnectedChars.Count > World.允许最大连接数)
					{
						World.线程同步变量 = true;
						if (this.T != null)
						{
							this.T.Stop();
							this.T = null;
						}
						Random random = new Random();
						World.游戏服务器端口1 = World.游戏服务器端口 + random.Next(10, 200);
						this.T = new RxjhServer.Network.Listener((ushort)World.游戏服务器端口1);
						World.端口更换通知();
						World.线程同步变量 = false;
					}

				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "FlushAll 错误" + ex.Message);
				if (!this.runn)
				{
					RxjhServer.Timer.DelayCall(TimeSpan.FromMilliseconds(180000.0), TimeSpan.FromMilliseconds(180000.0), new TimerCallback(this.自动公告事件));
					this.thThreadRead = new Thread(new ThreadStart(this.FlushAll));
					this.thThreadRead.Name = "FlushAll";
					this.thThreadRead.Start();
				}
			}
		}

		public void 自动公告事件()
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(0, "自动公告事件");
			}
			try
			{
				if (World.自动存档 == 1)
				{

					ParameterizedThreadStart start = new ParameterizedThreadStart(this.自动存档线程);
					Thread thread = new Thread(start);
					thread.Start();
				}
                if (World.Gamedayov <= 0)
                {
                    //Environment.Exit(0);
                }
                this.复查用户登陆();
				if (World.公告.Count > 0)
				{
					公告类 公告类 = World.公告[this.自动公告ID];
					Form1.公告发送(公告类.msg, 公告类.type);
					this.自动公告ID++;
					if (this.自动公告ID >= World.公告.Count)
					{
						this.自动公告ID = 0;
					}
				}
                if (World.allConnectedChars.Count > World.list.Count)
                {
                    Queue temzjlb = Queue.Synchronized(new Queue());
                    foreach (Players Playe in World.allConnectedChars.Values)
                    {
                        temzjlb.Enqueue(Playe);
                    }
                    while (temzjlb.Count > 0)
                    {
                        Players Playe = (Players)temzjlb.Dequeue();

                        if (!World.list.ContainsKey(Playe.人物全服ID))
                        {
                            //if (World.allConnectedChars.ContainsKey(Playe.人物全服ID))
                            //{
                            //Players fwnpc = (Players)World.allConnectedChars[Playe.人物全服ID];
                            World.allConnectedChars.Remove(Playe.人物全服ID);
                            //World.allConnectedChars.Remove(Playe.人物全服ID);
                            //}
                        }
                    }
                    if (World.allConnectedChars.Count > World.list.Count)
                    {
                        World.conn.Dispose();
                        menuItem3.PerformClick();
                        World.自动存档 = 0;
                    }
                }
                if (World.物品记录 == 1)
				{
					DBA.ExeSqlCommand("DELETE FROM 物品记录 WHERE  DateDiff(dd,时间,getdate())>" + World.记录保存天数);
				}
				if (World.登陆记录 == 1)
				{
					DBA.ExeSqlCommand("DELETE FROM 登陆记录 WHERE  DateDiff(dd,时间,getdate())>" + World.记录保存天数);
					DBA.ExeSqlCommand("DELETE FROM TBL_传书系统 WHERE  DateDiff(dd,传书时间,getdate())>" + World.记录保存天数);
				}
				if (World.PK记录 == 1)
				{
					DBA.ExeSqlCommand("DELETE FROM TBL_PK记录 WHERE  DateDiff(dd,时间,getdate())>" + World.记录保存天数);
				}
			}
			catch
			{
			}
		}

		public static void 公告发送(string txt, int type)
		{
			try
			{
				foreach (Players current in World.allConnectedChars.Values)
				{
					if (current != null)
					{
						if (type == 0)
						{
							current.系统公告(txt);
						}
						else
						{
							current.系统滚动公告(txt);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "SetLogs 错误" + ex.Message);
			}
		}

		private void timer1_Tick(object source, EventArgs e)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(0, "timer1_Tick");
			}
			this.GraphPanel.Invalidate();
			this.statusBarPanel1.Text = string.Concat(new object[]
			{
				"连接:",
				World.list.Count.ToString(),
				" 在线:",
				World.allConnectedChars.Count,
				"/",
				World.allConnectedChars.Count
			});


			
			int CC差距数 = 0;
			World.本次IP连接数 = World.list.Count;

			//CC差距数 = World.本次IP连接数 - World.上次IP连接数;
			CC差距数 = World.list.Count- World.allConnectedChars.Count;//连接-在线=CC差距数属于CC攻击 
			if (World.有攻击 == 0)//检查攻击类型
			{  // World.接收速度 1024=1k     2M=2024000   100人约 100K1秒  超过2M为攻击封包 属于流量攻击

				if((World.接收速度 > 1024000)&&(World.接收速度 < 2024000))//流量攻击 1 阶段1MB
				{

					World.有攻击 = 1;
					World.被攻击CC防御剩余秒 = 50;//防御秒 50秒重新恢复玩家登陆

				}
				else if ((World.接收速度 > 2024000) && (World.接收速度 < 3024000))//流量攻击 2 阶段2MB
				{

					World.有攻击 = 1;
					World.被攻击CC防御剩余秒 = 80;//防御秒 80秒重新恢复玩家登陆

				}
				else if (World.本次IP连接数 >= 800 || CC差距数 >= 100  )//CC攻击
				{
					World.被攻击CC防御剩余秒 = World.被攻击叠加10秒;//自动防御秒
					World.有攻击 = 1;
				}
				else
				{

					World.上次IP连接数 = World.本次IP连接数;
				}
			}
			//游戏登陆端口最大连接时间数

			if (World.有攻击 ==1)//开始防御
			{
				World.有攻击 = World.有攻击 + 1;
				
				World.本次IP连接数 = 0;
				World.上次IP连接数 = 0;
				World.游戏登陆端口最大连接时间数 = 1;
				World.被攻击防御次数 = World.被攻击防御次数 + 1;

				Random random = new Random();
				int 临时端口 = World.游戏服务器端口 + random.Next(50, 500);
				if (this.T != null)
				{
					this.T.Stop();
					this.T = null;
				}
				this.T = new RxjhServer.Network.Listener((ushort)临时端口);
				World.端口更换通知();

				Form1.WriteLine(1, "[有傻逼在攻击]临时切换端口>" + 临时端口 + "|"+ World.被攻击叠加10秒 + "秒后恢复>"+ World.游戏服务器端口);
				World.被攻击叠加10秒 = World.被攻击叠加10秒 + 10;
				if(World.被攻击叠加10秒>=30)
				{
					World.被攻击叠加10秒 = 10;
				}
			}
			if (World.被攻击CC防御剩余秒>=1)//解除防御恢复端口
			{
				World.被攻击CC防御剩余秒 = World.被攻击CC防御剩余秒 - 1;
				if(World.被攻击CC防御剩余秒==0)
				{
					World.游戏登陆端口最大连接时间数 = 15;
					World.有攻击 = 0;
					if (this.T != null)
					{
						this.T.Stop();
						this.T = null;
					}
					this.T = new RxjhServer.Network.Listener((ushort)World.游戏服务器端口);
					World.端口更换通知();

					Form1.WriteLine(1, "被攻击后恢复端口>" + World.游戏服务器端口);

				}

			}
			if(World.被攻击防御次数 >=1)
			{  if (World.有攻击 >=1)
				{
					Form1.WriteLine(2, "服务器拦截攻击[" + World.被攻击防御次数 + "次] 防御时间剩[" + World.被攻击CC防御剩余秒 + "秒] 当前状态[游戏登陆关闭]");
				}
				else
				{
					Form1.WriteLine(2, "服务器拦截攻击[" + World.被攻击防御次数 + "次] 当前状态[游戏登陆畅通]");
				}
			}

			this.statusBarPanel2.Text = string.Concat(new object[]
			{
				"地图物品:",
				World.ItmeTeM.Count.ToString(),
				" 怪物:",
				MapClass.GetNpcConn()
			});
			double num = World.接收速度;
			double num2 = World.发送速度;
			double num3 = World.广播发送速度;
			string text;
			if (num >= 1024.0)
			{
				num = World.接收速度 / 1024.0;
				text = Math.Round(num, 0).ToString() + "K";
			}
			else
			{
				text = Math.Round(num, 0).ToString() + "B";
			}
			string text2;
			if (num2 >= 1024.0)
			{
				num2 = World.发送速度 / 1024.0;
				text2 = Math.Round(num2, 0).ToString() + "K";
			}
			else
			{
				text2 = Math.Round(num2, 0).ToString() + "B";
			}
			if (num3 >= 1024.0)
			{
				num3 = World.广播发送速度 / 1024.0;
				//Math.Round(num3, 0).ToString() + "K";
			}
			else
			{
				//Math.Round(num3, 0).ToString() + "B";
			}
			this.statusBarPanel3.Text = string.Concat(new string[]
			{
				"收:",
				text,
				"/s 发:",
				text2,
				"/s 包:",
				Converter.Hexstring.Count.ToString()
			});
			World.接收速度 = 0.0;
			World.发送速度 = 0.0;
			World.广播发送速度 = 0.0;
			TimeSpan timeSpan = DateTime.Now.Subtract(this.sj);
			this.statusBarPanel4.Text = string.Concat(new string[]
			{
				timeSpan.Days.ToString(),
				"天",
				timeSpan.Hours.ToString(),
				"时",
				timeSpan.Minutes.ToString(),
				"分",
				timeSpan.Seconds.ToString(),
				"秒"
			});


			if (World.寄售时间秒 > 0)
			{
				World.寄售时间秒 = World.寄售时间秒 + 1;
				if (World.寄售时间秒 >= 3)
				{
					World.寄售时间秒 = 0;
					Form1.WriteLine(2, "寄售解锁");
				}
			}

		}

		private void menuItem29_Click(object sender, EventArgs e)
		{
			if (!this.runn)
			{
				this.runn = true;
				Form1.timerThread.Abort();
				this.thThreadRead.Abort();
				return;
			}
			this.thThreadRead = new Thread(new ThreadStart(this.FlushAll));
			this.thThreadRead.Name = "FlushAll";
			this.thThreadRead.Start();
			RxjhServer.Timer.TimerThread @object = new RxjhServer.Timer.TimerThread();
			Form1.timerThread = new Thread(new ThreadStart(@object.TimerMain));
			Form1.timerThread.Name = "Timer Thread";
			Form1.timerThread.Start();
		}

		private void menuItem5_Click(object sender, EventArgs e)
		{
			UserList userList = new UserList();
			userList.ShowDialog();
		}

		private void menuItem27_Click(object sender, EventArgs e)
		{
			FormUser组队 formUser组队 = new FormUser组队();
			formUser组队.ShowDialog();
		}

		private void menuItem7_Click(object sender, EventArgs e)
		{
			Form1.world.SetMonSter();
			Form1.world.SetNpc();
			Form1.world.SetDrop();
			Form1.world.Set_GSDrop();
			Form1.world.SetBossDrop();
			Form1.world.SetOpen();
			Form1.world.SetLever();
			Form1.world.SetPatLever();
			Form1.world.SetWxLever();
			Form1.world.SetKONGFU();
			Form1.world.SetItme();
			Form1.world.SetShot();
			Form1.world.SetMover();
			Form1.world.Set公告();
			Form1.world.Set异口同声();
			Form1.world.Set移动();
			Form1.world.Set安全区();
			Form1.world.SetKill();
			Form1.world.Set冲关地图();
			Form1.world.SetBossInfo();
			Form1.world.Set百宝物品();
			Form1.world.set会员装备();
			Form1.world.Set套装物品();
			Form1.world.Set转职属性();
			Form1.world.Set冲级奖励物品();
			Form1.world.SetScript();
			Form1.world.SetDB首爆();
		}

		private void menuItem8_Click(object sender, EventArgs e)
		{
			Form1.world.SetMonSter();
		}

		private void menuItem9_Click(object sender, EventArgs e)
		{
			Form1.world.SetDrop();
		}

		private void menuItem10_Click(object sender, EventArgs e)
		{
			Form1.world.SetOpen();
		}

		private void menuItem11_Click(object sender, EventArgs e)
		{
			Form1.world.SetItme();
		}

		private void menuItem12_Click(object sender, EventArgs e)
		{
			Form1.world.SetShot();
		}

		private void menuItem13_Click(object sender, EventArgs e)
		{
			Form1.world.SetMover();
			Form1.world.Set移动();
			Form1.world.Set安全区();
		}

		private void menuItem14_Click(object sender, EventArgs e)
		{
			Form1.world.Set异口同声();
			Form1.world.Set公告();
		}

		private void menuItem15_Click(object sender, EventArgs e)
		{
			if (this.menuItem15.Checked)
			{
				this.menuItem15.Checked = false;
				World.Log = 0;
				return;
			}
			this.menuItem15.Checked = true;
			World.Log = 1;
		}

		private void menuItem26_Click(object sender, EventArgs e)
		{
			if (this.menuItem26.Checked)
			{
				this.menuItem26.Checked = false;
				World.jlMsg = 0;
				return;
			}
			this.menuItem26.Checked = true;
			World.jlMsg = 1;
		}

		private void menuItem16_Click(object sender, EventArgs e)
		{
			Form1.world.SetConfig();
			World.conn.发送(string.Concat(new object[]
			{
				"更新服务器配置|",
				World.服务器ID,
				"|",
				World.最大在线
			}));
			Form1.WriteLine(2, "重新加载服务器配置方件完成");
		}

		private void menuItem17_Click(object sender, EventArgs e)
		{
			ParameterizedThreadStart start = new ParameterizedThreadStart(this.自动存档线程);
			Thread thread = new Thread(start);
			thread.Start();
		}

		private void menuItem18_Click(object sender, EventArgs e)
		{
			if (this.menuItem18.Checked)
			{
				this.menuItem18.Checked = false;
				World.验证服务器log = 0;
				return;
			}
			this.menuItem18.Checked = true;
			World.验证服务器log = 1;
		}

		private void menuItem19_Click(object sender, EventArgs e)
		{
			if (this.menuItem19.Checked)
			{
				this.menuItem19.Checked = false;
				World.jllog = 0;
				return;
			}
			this.menuItem19.Checked = true;
			World.jllog = 1;
		}

		private void menuItem20_Click(object sender, EventArgs e)
		{
			if (this.menuItem20.Checked)
			{
				this.menuItem20.Checked = false;
				World.AlWorldlog = false;
				return;
			}
			this.menuItem20.Checked = true;
			World.AlWorldlog = true;
		}

		private void menuItem21_Click(object sender, EventArgs e)
		{
			try
			{
				if (this.menuItem21.Checked)
				{
					this.menuItem21.Checked = false;
					World.AllItmelog = 0;
				}
				else
				{
					this.menuItem21.Checked = true;
					World.AllItmelog = 1;
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "查物品错误    错误" + ex.Message);
			}
		}

		private void menuItem22_Click(object sender, EventArgs e)
		{
			Form1.world.SetNpc();
		}

		private void menuItem23_Click(object sender, EventArgs e)
		{
			Form1.world.SetBossDrop();
		}

		private void menuItem24_Click(object sender, EventArgs e)
		{
		}

		private void menuItem25_Click(object sender, EventArgs e)
		{
			Form1.world.Set_GSDrop();
		}

		private void menuItem28_Click(object sender, EventArgs e)
		{
			Form1.world.SetKill();
		}

		private void menuItem30_Click(object sender, EventArgs e)
		{
			Form1.world.SetKONGFU();
		}

		private void toolStripButton1_Click(object sender, EventArgs e)
		{
			this.aaa++;
		}

		public void Send单包(byte[] toSendBuff, int len)
		{
			int num = (int)BitConverter.ToInt16(toSendBuff, 9);
			byte[] array = new byte[num + 7];
			Buffer.BlockCopy(toSendBuff, 5, array, 0, array.Length);
			this.Send封装发送(array, array.Length);
		}

		private void Send封装发送(byte[] toSendBuff, int length)
		{
			byte[] array = new byte[length + 15];
			array[0] = 170;
			array[1] = 85;
			Buffer.BlockCopy(BitConverter.GetBytes(length + 9), 0, array, 2, 2);
			Buffer.BlockCopy(toSendBuff, 0, array, 5, length);
			array[array.Length - 2] = 85;
			array[array.Length - 1] = 170;
			string value = Converter.ToString(array);
			Console.WriteLine(value);
		}

		private void toolStripButton2_Click(object sender, EventArgs e)
		{
			try
			{
				foreach (Players current in World.allConnectedChars.Values)
				{
				}
			}
			catch
			{
			}
		}

		private void toolStripButton3_Click(object sender, EventArgs e)
		{
			this.复查用户登陆();
		}

		private void toolStripButton4_Click(object sender, EventArgs e)
		{
			try
			{
				foreach (MapClass current in World.Map.Values)
				{
					foreach (NpcClass current2 in current.npcTemplate.Values)
					{
						current2.getbl();
					}
				}
				foreach (组队Class current3 in World.W组队.Values)
				{
					Form1.WriteLine(2, string.Concat(new object[]
					{
						"组队:",
						current3.组队id,
						" 人物：",
						current3.组队列表.Count
					}));
					foreach (Players current4 in current3.组队列表.Values)
					{
						Form1.WriteLine(2, "组队员:" + current4.Userid + " 人物：" + current4.UserName);
					}
				}
				foreach (Players arg_163_0 in World.allConnectedChars.Values)
				{
				}
				foreach (object current5 in World.locklist3)
				{
					Form1.WriteLine(2, current5.ToString());
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, ex.ToString());
			}
			GC.Collect();
		}

		public void 复查用户登陆()
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				foreach (NetState current in World.list.Values)
				{
					stringBuilder.Append(current.Player.Userid);
					stringBuilder.Append("-");
					stringBuilder.Append(current.Player.Client.绑定帐号);
                    stringBuilder.Append("-");
                    stringBuilder.Append(current.Player.UserName);
                    if (current.Player.是否人物离线挂机)
					{
						stringBuilder.Append("-1");
					}
                    stringBuilder.Append(",");
				}
				if (stringBuilder.Length > 0)
				{
					stringBuilder.Remove(stringBuilder.Length - 1, 1);
				}
				World.conn.发送("复查用户登陆|" + stringBuilder);
				GC.Collect();
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "复查用户登陆 错误" + ex.Message);
			}
		}

		private void GraphPanel_Paint(object sender, PaintEventArgs e)
		{
			try
			{
				Graphics graphics = e.Graphics;
				graphics.SmoothingMode = SmoothingMode.AntiAlias;
				graphics.PixelOffsetMode = PixelOffsetMode.None;
				string s = string.Concat(new object[]
				{
					"连接:",
					World.list.Count.ToString(),
					"/",
					World.最大在线,
					" 在线:",
					World.allConnectedChars.Count,
					"/",
					World.allConnectedChars.Count,
					" 主Socket:",
					World.主Socket.ToString(),
					" SocketState:",
					World.SocketState,
					" 组队:",
					World.W组队.Count,
					" 离线队列:",
					World.m_Disposed.Count,
					" 数据库队列:",
					World.SqlPool.Count,
					" 狮子列队:",
					World.狮子吼List.Count.ToString()
				});
				graphics.DrawString(s, Control.DefaultFont, Brushes.Black, new Point(20, 5));
				this.Text = string.Concat(new string[]
				{
					"GS2020_",
					World.服务器名,
					"_",
					World.游戏服务器端口1.ToString(),
					"_",
					Assembly.GetExecutingAssembly().GetName().Version.ToString()
				});
				int num = 0;
				foreach (TxtClass current in Form1.txt)
				{
					switch (current.type)
					{
					case 0:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Black, new Point(5, num += 17));
						break;
					case 1:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Red, new Point(5, num += 17));
						break;
					case 2:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Black, new Point(5, num += 17));
						break;
					case 3:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Green, new Point(5, num += 17));
						break;
					case 4:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Teal, new Point(5, num += 17));
						break;
					case 5:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.DodgerBlue, new Point(5, num += 17));
						break;
					case 6:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Blue, new Point(5, num += 17));
						break;
					default:
						graphics.DrawString(current.Txt, Control.DefaultFont, Brushes.Black, new Point(5, num += 17));
						break;
					}
				}
			}
			catch
			{
			}
		}

		public static void WriteLine(int type, string txtt)
		{
			int num = Form1.kjdx / 18;
			lock (Form1.txt)
            {
                if (type == 98)
                {
                    logo.qjfuzhi(txtt);
                }
                if (type == 100)
				{
					logo.FileTxtLog(txtt);
					Form1.txt.Add(new TxtClass(type, DateTime.Now.ToString() + " " + txtt));
					int count = Form1.txt.Count;
					if (num <= 0)
					{
						num = 20;
					}
					if (count > num)
					{
						for (int i = 0; i < count - num; i++)
						{
							Form1.txt.RemoveAt(0);
						}
					}
				}
				else if (World.AlWorldlog)
				{
					if (World.jllog == 1)
					{
						if (type == 1)
						{
							logo.FileTxtLog(txtt);
						}
						else if (type == 2)
						{
							logo.FileCQTxtLog(txtt);
						}
						else if (type == 3)
						{
							logo.FileLoninTxtLog(txtt);
						}
						else if (type == 4)
						{
							logo.FileDropItmeTxtLog(txtt);
						}
						else if (type == 5)
						{
							logo.FileItmeTxtLog(txtt);
						}
						else if (type == 6)
						{
							logo.FileBugTxtLog(txtt);
						}
						else if (type == 7)
						{
							logo.FilePakTxtLog(txtt);
						}
						else if (type == 8)
						{
							logo.SeveTxtLog(txtt);
						}
					}
					if (type == 99)
					{
						logo.FileTxtLog(txtt);
					}
					else if (type == 88)
					{
						logo.pzTxtLog(txtt);
					}
					else if (type == 77)
					{
						logo.cfzTxtLog(txtt);
					}
					else if (type == 44)
					{
						logo.Logout(txtt);
					}

                    else if (type == 55 && World.记录再造)
					{
						logo.FileReMakeTxtLog(txtt);
					}
					Form1.txt.Add(new TxtClass(type, DateTime.Now.ToString() + " " + txtt));
					int count2 = Form1.txt.Count;
					if (num <= 0)
					{
						num = 20;
					}
					if (count2 > num)
					{
						for (int j = 0; j < count2 - num; j++)
						{
							Form1.txt.RemoveAt(0);
						}
					}
				}
			}
		}

		private void menuItem31_Click(object sender, EventArgs e)
		{
			if (this.T != null)
			{
				NetSet netSet = new NetSet(this.T.Server);
				netSet.Show();
			}
		}

		private void menuItem33_Click(object sender, EventArgs e)
		{
			new Thread(new ThreadStart(Form2.FlushAll1))
			{
				Name = "Timer Thread"
			}.Start();
		}

		private void menuItem34_Click(object sender, EventArgs e)
		{
			new Thread(new ThreadStart(Form2.FlushAll2))
			{
				Name = "Timer Thread"
			}.Start();
		}

		private void menuItem35_Click(object sender, EventArgs e)
		{
		}

		private void menuItem36_Click(object sender, EventArgs e)
		{
			new Thread(new ThreadStart(Form2.FlushAll4))
			{
				Name = "Timer Thread"
			}.Start();
		}

		private void Form1_Layout(object sender, LayoutEventArgs e)
		{
			if (this.GraphPanel.Height != 0)
			{
				Form1.kjdx = this.GraphPanel.Height;
			}
		}

		private void menuItem37_Click(object sender, EventArgs e)
		{
			Form2 form = new Form2();
			form.ShowDialog();
		}

		private void menuItem38_Click(object sender, EventArgs e)
		{
			if (this.menuItem38.Checked)
			{
				this.menuItem38.Checked = false;
				World.Droplog = false;
				return;
			}
			this.menuItem38.Checked = true;
			World.Droplog = true;
		}

		private void menuItem39_Click(object sender, EventArgs e)
		{
			Form1.world.SetScript();
		}

		private void menuItem41_Click(object sender, EventArgs e)
		{
			SendGG sendGG = new SendGG();
			sendGG.ShowDialog();
		}

		private void menuItem42_Click(object sender, EventArgs e)
		{
		}

		private void menuItem43_Click(object sender, EventArgs e)
		{
		}

		private void menuItem44_Click(object sender, EventArgs e)
		{
			Form1.world.Set百宝物品();
		}

		private void menuItem45_Click(object sender, EventArgs e)
		{
			new Thread(new ThreadStart(Form2.FlushAll3))
			{
				Name = "Timer Thread"
			}.Start();
		}

		private void menuItem46_Click(object sender, EventArgs e)
		{
			if (World.eve == null)
			{
				World.eve = new EventClass(3);
                Form1.WriteLine(1, "3势力战开始！");
                this.menuItem46.Text = "关闭三势力战";
                return;
			}
			World.eve.Dispose();
			Form1.WriteLine(1, "3势力战结束！");
			this.menuItem46.Text = "开启三势力战";
		}

		private void menuItem47_Click(object sender, EventArgs e)
		{
			Form1.world.set会员装备();
			Form1.world.Set套装物品();
		}

		private void menuItem48_Click(object sender, EventArgs e)
		{
		}

		private void menuItem49_Click(object sender, EventArgs e)
		{
		}

		private void menuItem50_Click(object sender, EventArgs e)
		{
			Form1.world.set会员装备();
			Form1.world.Set转职属性();
			Form1.world.Set冲级奖励物品();
		}

		private void menuItem51_Click(object sender, EventArgs e)
		{
			Form1.world.Set任务物品();
			Form1.world.Set任务传书数据();
		}

		private void menuItem49_Click_1(object sender, EventArgs e)
		{
			if (this.T != null)
			{
				this.T.Stop();
				this.T = null;
			}
			Random random = new Random();
			World.游戏服务器端口1 = World.游戏服务器端口 + random.Next(10, 200);
			this.T = new RxjhServer.Network.Listener((ushort)World.游戏服务器端口1);
			World.端口更换通知();
		}

		private void menuItem52_Click(object sender, EventArgs e)
		{
		}

		private void menuItem53_Click(object sender, EventArgs e)
		{
		}

		private void menuItem54_Click(object sender, EventArgs e)
		{
			SendItem sendItem = new SendItem();
			sendItem.ShowDialog();
		}

		private void menuItem24_Click_1(object sender, EventArgs e)
		{
			if (World.门战进程 == 0)
			{
				if (World.门战 != null)
				{
					World.门战.Dispose();
					World.门战 = null;
				}
				World.门战 = new 帮派战_门战();
				Form1.WriteLine(1, "新门战开始！");
				this.menuItem24.Text = "结束新门战";
				return;
			}
			if (MessageBox.Show("门战正在进行中确定要重结束么？", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
			{
				if (World.门战 != null)
				{
					World.门战.Dispose();
					World.门战 = null;
				}
				Form1.WriteLine(1, "新门战结束！");
				this.menuItem24.Text = "开启新门战";
			}
		}

		private void menuItem33_Click_1(object sender, EventArgs e)
		{
			if (World.是否开启高倍经验 == 0)
			{
				World.是否开启高倍经验 = 1;
				World.发送公告(World.高倍经验倍数 + "倍经验开启！");
				Form1.WriteLine(1, "高倍经验开启！");
			}
		}

		private void menuItem35_Click_1(object sender, EventArgs e)
		{
			if (this.menuItem35.Checked)
			{
				this.menuItem34.Checked = false;
				World.记录再造 = false;
				return;
			}
			this.menuItem35.Checked = true;
			World.记录再造 = true;
		}

		private void menuItem34_Click_1(object sender, EventArgs e)
		{
			if (this.menuItem34.Checked)
			{
				this.menuItem34.Checked = false;
				World.记录掉落 = false;
				return;
			}
			this.menuItem34.Checked = true;
			World.记录掉落 = true;
		}

		private void menuItem36_Click_1(object sender, EventArgs e)
		{
		}

		private void menuItem42_Click_1(object sender, EventArgs e)
		{
			Form1.world.SetBossInfo();
		}

        private void menuItem43_Click_1(object sender, EventArgs e)
        {
            Form9 npcList = new Form9();
            npcList.StartPosition = FormStartPosition.CenterParent;
            npcList.ShowDialog();
        }

        private void menuItem45_Click_1(object sender, EventArgs e)
        {
            Move npcList = new Move();
            npcList.StartPosition = FormStartPosition.CenterParent;
            npcList.ShowDialog();
        }

        private void menuItem48_Click_1(object sender, EventArgs e)
        {
            if (World.eve == null)
            {
                World.eve = new EventClass(3);
                Form1.WriteLine(1, "4势力战开始！");
                this.menuItem46.Text = "关闭四势力战";
                return;
            }
            World.eve.Dispose();
            Form1.WriteLine(1, "4势力战结束！");
            this.menuItem46.Text = "开启四势力战";
        }

        private void menuItem52_Click_1(object sender, EventArgs e)
        {
            CheckCopy npcList = new CheckCopy();
            npcList.StartPosition = FormStartPosition.CenterParent;
            npcList.ShowDialog();
        }

        private void menuItem53_Click_1(object sender, EventArgs e)
        {
            Form1.world.Set石头属性();
        }

        private void menuItem55_Click(object sender, EventArgs e)
        {
            石头属性调整 npcList = new 石头属性调整();
            npcList.StartPosition = FormStartPosition.CenterParent;
            npcList.ShowDialog();
        }
    }
}
